{extend name="public/base"}

{block name="x-body"}
<style>
    #test9 {
        display: none;
    }

    #demo1 {
        width: 200px;
    }
</style>
<div class="x-body">
    <form class="layui-form">
        {if !$id}
            <input type="hidden" name="pid" value="0">
        {else /}
            <input type="hidden" name="id" value="{$res.id}">

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>上级分类
                </label>

                <div class="layui-input-block">
                    <select name="pid">
                        <option value="0">顶级分类</option>
                        {volist name="res.list" id="v"}
                        <option value="{$v.id}" {if $type}{if $v.id == $res.id}selected{/if}{else /}{if $v.id == $res.pid}selected{/if}{/if}>{for start="0" end="$v.level"}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{/for}{$v.cate_name}</option>
                        {/volist}
                    </select>
                </div>

                <div class="layui-form-mid layui-word-aux">
                    <label class="layui-form-label"></label>如果选择当前分类为上级分类，则在当前分类下添加分类
                </div>
            </div>
        {/if}

        <div class="layui-form-item">
            <label for="cate_name" class="layui-form-label">
                <span class="x-red">*</span>分类名
            </label>
            <div class="layui-input-block">
                <input type="text" id="cate_name" name="cate_name" placeholder="顶级分类名" value="{if !$type}{$res.cate_name}{/if}" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-upload layui-form-item">
            <label class="layui-form-label">
                分类图标
            </label>
            <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
            <button type="button" class="layui-btn" id="test9">开始上传</button>
            <input type="hidden" name="icon" value="{$res.icon}" id="ad_img">

            <div class="layui-upload-list" style="display: {if !$res.icon || $type}none{/if};">
                <label class="layui-form-label"></label>
                <img class="layui-upload-img" id="demo1" src="{if $res}{:config('imgRoute')}{$res.icon}{/if}">
                <p id="demoText"></p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                {if $id}
                    {if $type}
                        增加
                    {else /}
                        修改
                    {/if}
                {else}
                    增加
                {/if}
            </button>
        </div>
    </form>
</div>
<script>
    formData('{:url("goods/goodsCate_form")}', 'add', function (){
        parent.location.reload();
        // 获得frame索引
        var index = parent.layer.getFrameIndex(window.name);
        //关闭当前frame
        parent.layer.close(index);
    }, false);

    layui.use(['form', 'upload'], function(){
        var upload = layui.upload;

        uploadImg(upload, '{:url("goods_upload")}');
    });
</script>
{/block}